/**
 * this plugin is rquire this tag to embed in your page. 
 * <script src="//platform.linkedin.com/in.js" type="text/javascript">lang: en_US;</script>
 * <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
 * <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
 * 
 * 
 */


(function( $ ){
  $.fn.pc_socmed = function( config ) {  
      this.pc_data_include = '';
      this.pc_html = '';
      this.pc_domainname = '';
      
      this.pc_create_fb = function(url) {
          var html = '<iframe ' +
              'src="//www.facebook.com/plugins/like.php?href='+url+'&amp;send=false&amp;layout=box_count&amp;width=50&amp;show_faces=true&amp;font&amp;colorscheme=light&amp;action=like&amp;height=90"'+
              'scrolling="no" frameborder="0" allowTransparency="true"' +
              'style="border:none; overflow:hidden; width:50px; height:61px;">' +
              '</iframe>';
          //$(this).append(html);
          return html;
      };
      
      this.pc_create_linkedin = function(url) {
          var html = '<script type="IN/Share" data-url="'+url+'" data-counter="top"></script>';
          //$(this).append(html);
          return html;
      };
      
      this.pc_create_twitter = function(url) {
          var html = '<a href="https://twitter.com/share" data-counturl="'+url+'" class="twitter-share-button twitter-count-vertical" data-count="vertical" data-dnt="true">Tweet</a>'
          //$(this).append(html);
          return html;
      };
      
      this.pc_create_gplus = function() {
          var html = '<g:plusone annotation="bubble" size="tall"></g:plusone>';
          //$(this).append(html);
          return html;
      };
      
      this.pc_create_close = function() {
          var html = '<div class="pc-close">close &times; </div>';
          //$(this).append(html);
          return html;
      };
      
      this.pc_get_current_url = function() {
          var resurl = "http://"+this.pc_domainname+"/";
          var cururl = document.URL;
          var strpatern = this.pc_domainname + "[^?#]*";
          var cururl = cururl.match(new RegExp(strpatern, 'i'));

          if (cururl != null) {
              resurl = "http://"+cururl[0];
          }
          
          return resurl;
      };

      this.pc_ctrl_posisi = function() {
          that = $(this);
          var positionlimit = $(".main-outer").offset().top;
          var bottomlimit = $(".footer-outer").offset().top;
          var height = $(this).height();
          
          $(document).scroll(function() {
              var pos = $(document).scrollTop();
              
              $(that).css({top: 0});
              if (positionlimit > pos) {
                  $(that).css({
                      bottom: "",
                      top: 0,
                      position: "absolute"
                  });
              } else if (bottomlimit < pos + height) {
                  $(that).css({
                      bottom: 0,
                      top: "",
                      position: "absolute"
                  });
              } else {
                  $(that).css({
                      bottom: "",
                      top: 0,
                      position: "fixed"
                  });
              }
          });
      };
      
      this.pc_init = function(config) {
          this.pc_domainname = config.domainname;
          var url = this.pc_get_current_url();
          var url_encode = encodeURIComponent(url);
          
          //$(this).append(this.pc_create_close());
          $(this).append(this.pc_create_fb(url_encode));
          $(this).append(this.pc_create_linkedin(url));
          $(this).append(this.pc_create_gplus() + "<br />");
          $(this).append(this.pc_create_twitter(url));
          
          this.pc_ctrl_posisi();
      };
      
      this.pc_init(config);
  };
})( jQuery );

